#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :AES加密算法.py
# @Time      :2024/4/12 14:30
# @Author    :Sherlock
import random
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64

key = "0123456789abcdef"
iv = "0123456789abcdef"


def encrypt_(text):
    # 创建加密算法对象
    cipher = AES.new(key.encode(), AES.MODE_CBC, iv.encode())
    # 使用算法对象进行加密
    encrypt_text = cipher.encrypt(pad(text.encode(), AES.block_size))
    # 返回加密后数据的base64编码字符串
    return base64.b64encode(encrypt_text).decode()


text = "今天天气真好"
print(encrypt_(text))
